package com.duanjw.springframework.configuration.service.impl;

import com.duanjw.springframework.configuration.imports.MyInvocationHandler;
import com.duanjw.springframework.configuration.service.UserService;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * 用户serviceImpl
 *
 * @author duanjw
 */
public class UserServiceImpl2 implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if(beanName.equals("userServiceImpl")){
            bean = Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[]{UserService.class}, new MyInvocationHandler(bean));
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }
//
//    /**
//     * 查询
//     */
//    @Override
//    public void query() {
//        System.out.println("UserServiceImpl2.query");
//    }
}
